#include "global.h"
#include <QDebug>

static AppConfig *gConf = nullptr;


AppConfig *GetConfig()
{
  if(nullptr == gConf)
    gConf = new AppConfig;
  QFile *file = new QFile("config.json");
  file->open(QIODevice::ReadWrite);
  if(!file->exists()){
    qDebug()<<"fsdfasd";
  }
  QByteArray buf = file->readAll();
  qDebug()<<buf;
  if(buf.size() == 0){
    QJsonDocument c;
    QJsonObject obj;
    obj.insert("path","");
    c.setObject(obj);
    file->write(c.toJson().data(),c.toJson().size());
  }else{
    QJsonDocument p  = QJsonDocument::fromJson(buf);
    qDebug()<<p;
    QJsonObject ob =  p.object();
    qDebug()<<ob<<ob.value("path").toString();
    gConf->path = ob.value("path").toString();
  }
  file->close();
  return gConf;
}
void SetConfig(AppConfig *p){
  if (nullptr == p){
      return;
    }
  QFile *file = new QFile("config.json");
  file->open(QIODevice::ReadWrite);
  if(!file->exists()){
  }

  QJsonDocument c;
  QJsonObject obj;
  obj.insert("path",p->path);
  c.setObject(obj);
  file->write(c.toJson().data(),c.toJson().size());

  file->close();

}




